﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Windows;
using System.Windows.Threading;
using ExamSharedClasses;
using ExamClient;
using System.Windows.Controls.Primitives;


namespace ExamClient
{
    /// <summary>
    /// Hier werden statisch wichtige Referezen auf Fenster, Frames, Verbindungen gehalten,
    /// damit überall vom Programm aus zugegriffen werden kann. Die Objekte setzen "ihre"
    /// Referenz in ihren Konstruktoren.
    /// </summary>
    public partial class App : Application
    {
        // Window-/Frame-Management
        new public static MainWindow MainWindow { get; set; }
        public static LoginBar LoginBar { get; set; }
        public static MenuBarPage MenuBar { get; set; }
        public static MainPage MainPage { get; set; }
        public static ExamPage ExamPage { get; set; }
        public static SummaryPage SummaryPage { get; set; }
        
        
        
        // Programm Kevin
        public const string VERSION = "0.00";
        public const string SOURCE = "client";

        public static ClientMethods ClientMethods { get; set; }
        public static ServerConnection ServerConnection { get; set; }

        public static Session Session { get; set; }                 // aktuelle Session
        public static UserAddress UserAddress { get; set; }         // .. User
        public static Password Password { get; set; }               // .. Passwort
        public static UserInformationPage UserInfoPage { get; set; }

        public static DispatcherTimer DispatcherTimer { get; set; } // für UpdateGui()
        public static int messageCountdown;

        public static void Display(object messageObject)
        {
            Display(messageObject, null);
        }
        public static void Display(object messageObject, object secondMessageObject)
        {
            StringBuilder sb = new StringBuilder(DateTime.Now + ": ");

            if (messageObject != null)
            {
                if (messageObject is Exception)
                    sb.Append(((Exception)messageObject).Message);
                else
                    sb.Append(messageObject.ToString());
            }
            if (secondMessageObject != null)
            {
                if (secondMessageObject is Exception)
                    sb.Append('\n' + ((Exception)secondMessageObject).Message);
                else
                    sb.Append('\n' + secondMessageObject.ToString());
            }

            string text = sb.ToString();
            if (text.Contains("Fehler"))
                Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine(text);                                                // Ausgabe auf Konsole
            Console.ForegroundColor = ConsoleColor.Gray;
            Tools.AppendStringToFile(text, App.SOURCE + "_log_1FensterClient.txt"); // Anhängen an Datei
        }
    }
}
